package com.mavenq.fly.test;

import org.junit.Test;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class JDK8Time {

    @Test
    public void testMonths() throws Exception {
        int num = 6;
        List<String> monthLis = new ArrayList<>();
        LocalDate localDate = LocalDate.now();
        for (int i = 1; i <= num; i++) {
            String date = localDate.minusMonths(i).format(DateTimeFormatter.ofPattern("yyyy-MM"));
            monthLis.add(date);
        }
        System.out.println(monthLis);
    }
}
